package org.jiangnantaste.activity;

import org.jiangnantaste.util.TabPage;

import android.content.Intent;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;
import android.widget.TabWidget;
import android.widget.TextView;


public class ListAllDeliveryOrderTabActivity extends TabPageActivity{
	private TabPageActivity outer = this;  	
	private Intent unfinishedIntent = null;
	private Intent finishedIntent = null;
	private Spinner spin = null;
	private TabPage unfinishedTabPage;
	private TabPage finishedTabPage;
	

	private final String LOGTAG = "ListAllDeliveryOrderTabActivity";
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.delivery_order_list_tab);
		InitViewPager();
		
		spin = (Spinner) findViewById(R.id.tabspinner);

		
		spin.setSelection(0, true);
        spin.setOnItemSelectedListener(new OnItemSelectedListener(){
        	@Override
    		public void onItemSelected(AdapterView arg0, View arg1, int arg2,
    				long arg3) {
        		String selectedtext = (String)spin.getSelectedItem();
        		String[] viewtexts = getResources().getStringArray(R.array.tabs);
        		if (selectedtext.equals(viewtexts[0])) {
        			outer.setPage(0);
        		} else {
        			outer.setPage(1);
        		}
    		}
    		@Override
    		public void onNothingSelected(AdapterView<?> arg0) {
    			outer.setPage(0);	
    		}	
        });        
	}
	

	private void InitViewPager() {
		finishedIntent = new Intent(this, ListAllDeliveryOrderStatusBoFinishedActivity.class);
		unfinishedIntent = new Intent(this, ListAllDeliveryOrderStatusBoUnFinishedActivity.class);
		unfinishedTabPage = new TabPage("未完成派送单", unfinishedIntent);
		finishedTabPage = new TabPage("已完成派送单", finishedIntent);
		addTabPage(unfinishedTabPage);	
		addTabPage(finishedTabPage);
		initTabPage();
	}

	public void switchActivity(int index) {
	setPage(index);
	}
		
	@Override
	protected void onPageSelected(int index) {
	super.onPageSelected(index);
	spin.setSelection(index);
	}

	public Intent getFinishedIntent() {
	return finishedIntent;
	}

	public Intent getUnFinishedIntent() {
	return unfinishedIntent;
	}
}
